package vip.xiaonuo.biz.modular.config.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Encryption {
    public static String encryptTo32BitMD5(String input) {
        try {
            // Create MD5 Digest
            MessageDigest md = MessageDigest.getInstance("MD5");
            // Digest the input
            md.update(input.getBytes());
            // Get the hash's bytes
            byte[] digest = md.digest();
            // Convert to hexadecimal
            StringBuilder hexString = new StringBuilder();
            for (byte b : digest) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }
            // Return the hex string
            return hexString.toString().substring(0, 10);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        String input = "983daee50c42";
        String encrypted = encryptTo32BitMD5(input);
        System.out.println("MD5 32-bit Encrypted String: " + encrypted);
    }
}
